package com.bravo.search.service;

import com.bravo.search.entity.Article;
import com.bravo.search.repository.ArticleSearchRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @author: Yuyong
 * @create: 2019-08-06 11:26
 **/


@Service
public class ArticleSearchService {

    @Autowired
    public ArticleSearchRepository articleSearchRepository;

    /**
     * 增加文章
     * @param article
     */
    public void add(Article article){
        articleSearchRepository.save(article);
    }

    public Page<Article> findByTitleLike(String keywords,int page,int size){
        PageRequest pageRequest = PageRequest.of(page -1 ,size);
         return articleSearchRepository.findByTitleOrContentLike(keywords,keywords,pageRequest);
    }
}
